package cn.anecansaitin.whimsy.mixin.common;

import cn.anecansaitin.whimsy.common.register.ModEffects;
import net.minecraft.world.entity.Entity;
import net.minecraft.world.entity.LivingEntity;
import net.minecraft.world.entity.player.Player;
import net.neoforged.neoforge.common.extensions.IEntityExtension;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.injection.At;
import org.spongepowered.asm.mixin.injection.Inject;
import org.spongepowered.asm.mixin.injection.ModifyVariable;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable;

@Mixin(Entity.class)
public abstract class EntityMixin implements IEntityExtension {
    @ModifyVariable(method = "collide", at = @At(value = "STORE"), ordinal = 2)
    public boolean modify$flag2(boolean flag2) {
        if (((Object)this) instanceof LivingEntity living && (living.hasEffect(ModEffects.ROCKET_PUNCH.get()) || living.hasEffect(ModEffects.IMPACT.get()))) {
            return true;
        }

        return flag2;
    }

    @ModifyVariable(method = "collide", at = @At(value = "STORE"), ordinal = 3)
    public boolean modify$flag3(boolean flag3) {
        if (((Object)this) instanceof LivingEntity living && (living.hasEffect(ModEffects.ROCKET_PUNCH.get()) || living.hasEffect(ModEffects.IMPACT.get()))) {
            return true;
        }

        return flag3;
    }

    @Inject(method = "isInvulnerable", at = @At(value = "HEAD"), cancellable = true)
    public void inject$isInvulnerable(CallbackInfoReturnable<Boolean> cir) {
        if (((Object)this) instanceof LivingEntity living && (living.hasEffect(ModEffects.METEOR_STRIKE.get()))) {
            cir.setReturnValue(true);
        }
    }

    @Inject(method = "isInvulnerableTo", at = @At(value = "HEAD"), cancellable = true)
    public void inject$isInvulnerableTo(CallbackInfoReturnable<Boolean> cir) {
        if (((Object)this) instanceof LivingEntity living && (living.hasEffect(ModEffects.METEOR_STRIKE.get()))) {
            cir.setReturnValue(true);
        }
    }
}
